@extends('layout.admin')

@section('styles')
    <link rel="stylesheet" type="text/css" href="{{ asset('assets/plugins/wangEditor/css/wangEditor.min.css') }}">
@endsection

@section('content')
    <div class="row">
        <div class="col-md-12 ">
            <!-- BEGIN SAMPLE FORM PORTLET-->
            <div class="portlet light bordered">
                <div class="portlet-title">
                    <div class="caption">
                        <i class="icon-settings font-dark"></i>
                        <span class="caption-subject font-dark sbold uppercase">编辑文章</span>
                    </div>
                </div>
                <div class="portlet-body form">
                    @if (count($errors) > 0)
                        <div class="alert alert-warning">
                            <strong>Warning!</strong>
                            <ul>
                                @foreach ($errors->all() as $error)
                                    <li>{{ $error }}</li>
                                @endforeach
                            </ul>
                        </div>
                    @endif
                    <form class="form-horizontal" role="form" method="post" action="{{ route("admin.article.editSave") }}">
                        {{ csrf_field() }}
                        <input type="hidden" name="id" value="{{ $article_info->id }}">
                        <div class="form-body">
                            <div class="form-group">
                                <label class="col-md-3 control-label">文章标题</label>
                                <div class="col-md-8">
                                    <input type="text" class="form-control" placeholder="标题" name="title" value="{{ $article_info->title }}">
                                    <span class="help-inline"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label">作者</label>
                                <div class="col-md-8">
                                    <input type="password" class="form-control" placeholder="{{ Auth::user()->name }}" readonly name="user_name"> </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label">文章分类（多选）</label>
                                <div class="col-md-8">
                                    <select multiple class="form-control" name="cates[]">
                                        @foreach($cates as $cate)
                                            <option value="{{ $cate->id }}" @if(in_array($cate->id, $article_info->cate_ids)) selected @endif>{{ $cate->name }}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label">文章内容</label>
                                <div class="col-md-9">
                                    <textarea class="form-control" rows="3" name="content" id="content" style="height:400px;max-height:500px;">{{ $article_info->content }}</textarea>
                                </div>
                            </div>
                        </div>
                        <div class="form-actions">
                            <div class="row">
                                <div class="col-md-offset-3 col-md-9">
                                    <button type="submit" class="btn green">发布</button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
            <!-- END SAMPLE FORM PORTLET-->
        </div>
    </div>

@endsection()

@section('script')
    <script type="text/javascript" src="{{ asset('assets/plugins/wangEditor/js/wangEditor.min.js') }}"></script>
    <script type="text/javascript">
        var editor = new wangEditor('content');
        editor.create();
    </script>
@endsection